package com.qdu.reducer;

import com.qdu.bean.RentCarBean;
import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class MaxUsageByWindspeedReducer extends Reducer<DoubleWritable, RentCarBean, DoubleWritable, RentCarBean> {

    private RentCarBean resultBean = new RentCarBean();

    @Override
    protected void reduce(DoubleWritable key, Iterable<RentCarBean> values, Context context) throws IOException, InterruptedException {
        int maxcasual = 0;
        int maxregistered = 0;
        int maxcount = 0;
        for (RentCarBean r:
                values) {
            if (r.getCasual() > maxcasual)
                maxcasual = r.getCasual();
            if (r.getRegistered() > maxregistered)
                maxregistered = r.getRegistered();
            maxcount = maxcasual + maxregistered;
        }

        resultBean.set1(maxregistered,maxcasual,maxcount);

        context.write(key,resultBean);
    }
}
